<?php


namespace app\api\unionpay\ysf;

class PayHttpClient
{
	public $url;
	public $data;
	public $resContent;
	public $errInfo;
	public $timeOut;
	public $responseCode;
	public function __construct()
	{
		$this->PayHttpClient();
	}
	public function PayHttpClient()
	{
		$this->url = "";
		$this->data = "";
		$this->resContent = "";
		$this->errInfo = "";
		$this->timeOut = 120;
		$this->responseCode = 0;
	}
	public function setReqContent($url, $data)
	{
		$this->url = $url;
		$this->data = $data;
	}
	public function getResContent()
	{
		return $this->resContent;
	}
	public function getErrInfo()
	{
		return $this->errInfo;
	}
	public function setTimeOut($timeOut)
	{
		$this->timeOut = $timeOut;
	}
	public function call()
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeOut);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_URL, $this->url);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $this->data);
		$res = curl_exec($ch);
		$this->responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
		if ($res == null) {
			$this->errInfo = "call http err :" . curl_errno($ch) . " - " . curl_error($ch);
			curl_close($ch);
			return false;
		} else {
			if ($this->responseCode != "200") {
				$this->errInfo = "call http err httpcode=" . $this->responseCode;
				curl_close($ch);
				return false;
			}
		}
		curl_close($ch);
		$this->resContent = $res;
		return true;
	}
	public function getResponseCode()
	{
		return $this->responseCode;
	}
}